import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;


public class Math {

	public HashMap<String,Integer> argFctPredefinie = new HashMap<String,Integer>();
	
	public HashMap<String,Method> methodFctPredefinie = new HashMap<String,Method>();
	
	
	public Math() {
		argFctPredefinie.put("somme", 2);
		argFctPredefinie.put("produit", 2);
		argFctPredefinie.put("division", 2);
		argFctPredefinie.put("soustraction", 2);
		
		Class c = Math.class;
		Method[] tab = c.getMethods();
		
		Method  m;
		for (int i=0;i<tab.length;i++) {
			m = tab[i];
			if(m.getName().equals("somme"))
				methodFctPredefinie.put("somme", m);
			
			if(m.getName().equals("produit"))
				methodFctPredefinie.put("produit", m);
			
			if(m.getName().equals("division"))
				methodFctPredefinie.put("division", m);
			
			if(m.getName().equals("soustraction"))
				methodFctPredefinie.put("soustraction", m);
			
			
		}    
	};
	
	
	public static Object somme(ArrayList<Object> v, HashMap<String, Object> penv)
	{	
		double sum = 0;
		boolean t= true;
		int n = 0;

		while(t && n<v.size()) {
			t = false;
			if (v.get(n) instanceof Double ) {
				t = true;
				sum = sum + (Double)v.get(n);
			}
			if(v.get(n) instanceof Integer) {
				t = true;
				sum = sum + (Integer)v.get(n);
			}	
		n++;	
		}			
		
		if(t)
			if(sum%1 == 0)
				return (int)sum;
			else
				return sum;
		else
			return null;
	}
	
	public static Object soustraction(ArrayList<Object> v, HashMap<String, Object> penv)
	{	
		double sum = 0;
		boolean t = false;
		int n = 1;
		
		if (v.get(0) instanceof Double) {
			sum = (Double)v.get(0);
			t = true;
		}
		if (v.get(0) instanceof Integer) {
			sum = (Integer)v.get(0);
			t = true;
		}
		
		while(t && n<v.size()) {
			t = false;
			if (v.get(n) instanceof Double ) {
				t = true;
				sum = sum - (Double)v.get(n);
			}
			if(v.get(n) instanceof Integer) {
				t = true;
				sum = sum - (Integer)v.get(n);
			}	
		n++;	
		}			
		
		if(t)
			if(sum%1 == 0)
				return (int)sum;
			else
				return sum;
		else
			return null;
	}
	
	
	public static Object produit(ArrayList<Object> v, HashMap<String, Object> penv)
	{	
		double sum = 1;
		boolean t= true;
		int n = 0;
		
		while(t && n<v.size()) {
			t = false;
			if (v.get(n) instanceof Double ) {
				t = true;
				sum = sum * (Double)v.get(n);
			}
			if(v.get(n) instanceof Integer) {
				t = true;
				sum = sum * (Integer)v.get(n);
			}	
		n++;	
		}			
		
		if(t)
			if(sum%1 == 0)
				return (int)sum;
			else
				return sum;
		else
			return null;
	}
	
	public static Object division(ArrayList<Object> v, HashMap<String, Object> penv)
	{	
		double sum = 1;
		boolean t= true;
		int n = 1;
		
		if (v.get(0) instanceof Double) {
			sum = (Double)v.get(0);
			t = true;
		}
		if (v.get(0) instanceof Integer) {
			sum = (Integer)v.get(0);
			t = true;
		}
		
		while(t && n<v.size()) {
			t = false;
			if (v.get(n) instanceof Double ) {
				t = true;
				sum = sum / (Double)v.get(n);
			}
			if(v.get(n) instanceof Integer) {
				t = true;
				sum = sum / (Integer)v.get(n);
			}	
		n++;	
		}			
		
		if(t)
			if(sum%1 == 0)
				return (int)sum;
			else
				return sum;
		else
			return null;
	}

	
}
